package com.banksoft.cps.controller.trans;

import com.banksoft.cps.bean.Company;
import com.banksoft.cps.bean.Practitioner;
import com.banksoft.cps.bean.SaleOrder;
import com.banksoft.cps.bean.TransportCompany;
import com.banksoft.cps.bean.query.SaleOrderQuery;
import com.banksoft.cps.bean.warpper.SaleOrderWarpper;
import com.banksoft.cps.controller.ControllerConstants;
import com.banksoft.cps.enums.Process;
import com.banksoft.cps.service.PractitionerService;
import com.banksoft.cps.service.SaleOrderService;
import com.banksoft.cps.util.PageUtils;
import com.banksoft.cps.util.UserContext;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by rongzhao.zhu on 2018/1/3.
 */
@Controller
@RequestMapping("/trans/saleOrder/")
public class TSaleOrderController extends ControllerConstants {
    @Autowired
    SaleOrderService saleOrderService;

    @Autowired
    private PractitionerService practitionerService;

    @RequestMapping(value = "list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String list(SaleOrderQuery query){
        TransportCompany transportCompany = (TransportCompany) UserContext.getUser();
        query.setTransportCompanyId(transportCompany.getId());
        List<SaleOrderWarpper> list =  saleOrderService.listWarpper(query);
        return toJSONString(createDataTip(list));
    }
    @RequestMapping(value = "count", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String count(SaleOrderQuery query){
        TransportCompany transportCompany = (TransportCompany) UserContext.getUser();
        query.setTransportCompanyId(transportCompany.getId());
        long count =  saleOrderService.count(query);
        long pageCount = PageUtils.getPage(count,query.getSize());
        return toJSONString(createDataTip(pageCount));
    }

    @RequestMapping(value = "find",produces = "application/json;charset=utf-8")
    @ResponseBody
    public String find(String id){
        SaleOrderWarpper saleOrder = saleOrderService.findWarpperById(id);
        return toJSONString(createDataTip(saleOrder));
    }
}
